package com.wealth.scsj.p_app.view.activity.depositmodel;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wealth.scsj.p_app.R;
import com.wealth.scsj.p_app.mydefinedview.payeditview.SelectPopupWindow;
import com.wealth.scsj.p_app.utils.DialogUtils;
import com.wealth.scsj.p_app.view.activity.BaseActivity;

/**
 * 押金首页
 */
public class DepositHomePageActivity extends BaseActivity implements View.OnClickListener,SelectPopupWindow.OnPopWindowClickListener {

    private TextView mToolbarTitle;
    private ImageView mToolbarTitleLeft;
    /**
     * 需要缴纳押金
     */
    private TextView mDepositMoneyBoolTv;
    /**
     * ¥300.00
     */
    private TextView mDepositMoneyMuchTv;
    /**
     * 押金权益：1、无限制接收订单；2、享受###优惠权益等。
     */
    private TextView mDepositDescriptionTv;
    /**
     * 立即缴纳
     */
    private Button mPayBtn;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_deposit_home_page);
    }

    @Override
    protected void initView() {

        mToolbarTitle = findViewById(R.id.toolbar_title);
        mToolbarTitleLeft = findViewById(R.id.toolbar_title_left);

        mDepositMoneyBoolTv = findViewById(R.id.deposit_money_bool_tv);
        mDepositMoneyMuchTv = findViewById(R.id.deposit_money_much_tv);
        mDepositDescriptionTv = findViewById(R.id.deposit_description_tv);
        mPayBtn = findViewById(R.id.pay_btn);

    }

    @Override
    protected void initListener() {
        mToolbarTitleLeft.setOnClickListener(this);
        mPayBtn.setOnClickListener(this);
    }

    @Override
    protected void initData() {

        mToolbarTitle.setText("押金");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.toolbar_title_left:
                finish();
                break;
            case R.id.pay_btn:
//                showPayWindow();
//                showPayEditWindow();
//                new DepositPaySuccessDialog(DepositHomePageActivity.this)
//                        .setTitleText("支付成功啦！哈哈哈")
//                        .setConfirmClickListener(null)
//                        .show();
                //.setCustomImage(R.drawable.custom_img)

//                new com.wealth.scsj.p_app.customview.DepositPaySuccessDialog(DepositHomePageActivity.this)
//                        .setTitleText("您是300元押金用户")
//                        .setContentText("申请退押金需要人工审核1~3个工作日，审核成功之后押金将退至您的平台账户余额，同时您将不再享有押金用户所有的特权。")
//                        .setCustomImage(R.mipmap.return_deposit_icon)
//                        .setCancelText("取消")
//                        .show();
                break;
        }
    }

    /**
     * 密码支付输入密码 弹窗
     */

    private SelectPopupWindow PayEditWindow;
    private void showPayEditWindow() {
        PayEditWindow = new SelectPopupWindow(DepositHomePageActivity.this, DepositHomePageActivity.this);
        Rect rect = new Rect();
        getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        int winHeight = getWindow().getDecorView().getHeight();
        PayEditWindow.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, winHeight - rect.bottom);
    }

    private void showPayWindow() {
        DialogUtils.getInstance()
                .with(DepositHomePageActivity.this)//上下文
                .setlayoutId(R.layout.choose_pay_type_layout)//布局文件  choose_pay_type_layout
                .setlayoutPosition(Gravity.BOTTOM)//位置
                .setlayoutAnimaType(0)//动画类型:0自下而上动画，1淡入淡出动画
                .setlayoutPading(0, 0, 0, 0)//与屏幕距离
                .setOnChildViewclickListener(new DialogUtils.ViewInterface() {
                    @Override
                    public void getChildView(View view, int layoutResId) {
                        //处理dialog内部控件的点击事件
                        //TextView callNoticeTv = view.findViewById(R.id.call_notice_tv);
                        LinearLayout mPayBtn= view.findViewById(R.id.comfirm_pay_btn_ll);
                        mPayBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });
                        view.findViewById(R.id.close_page_iv).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                DialogUtils.dismiss();
                            }
                        });
                    }
                })
                .show();
    }

    /**
     * 密码输入pop点击监听事件
     * @param psw
     * @param complete
     */
    @Override
    public void onPopWindowClickListener(String psw, boolean complete) {
        if(complete)
            Toast.makeText(this, "您输入的密码是"+psw, Toast.LENGTH_SHORT).show();
    }
}
